package com.cloudsigns.factorymanager2.engineering.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import android.widget.CheckBox;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringConstructContentBean;
import com.cloudsigns.factorymanager2.project.myinerface.ItemCheckedChangeListener;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tony on 2018/2/1.
 */

public class AddConstructContentAdapter extends BaseAdapter {
    private Context context;
    private List<EngineeringConstructContentBean> datas = new ArrayList<EngineeringConstructContentBean>();
    private LayoutInflater inflater;
    private String tag = "";
    private ItemClickListener itemClickListener;
    private ItemCheckedChangeListener itemCheckedChangeListener;


    public AddConstructContentAdapter(Context context, String tag) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.tag = tag;
    }

    public void setItemClickListener(ItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    public void setItemCheckedChangeListener(ItemCheckedChangeListener itemCheckedChangeListener) {
        this.itemCheckedChangeListener = itemCheckedChangeListener;
    }

    ;

    public void setData(List<EngineeringConstructContentBean> list) {
        this.datas.clear();
        if (null != list) {
            this.datas.addAll(list);
        }

    }


    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public EngineeringConstructContentBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_add_construct_content_for_engineering_dispatch_lv, null);
            holder.cb_item = (CheckBox)convertView.findViewById(R.id.cb_item);
            holder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);
            holder.tv_plan_start_date = (TextView) convertView.findViewById(R.id.tv_plan_start_date);
            holder.tv_plan_end_date = (TextView) convertView.findViewById(R.id.tv_plan_end_date);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        EngineeringConstructContentBean bean = datas.get(position);
//        holder.cb_item.setChecked(bean.getChecked());
//        holder.tv_content.setText(bean.getContent());
//        holder.tv_plan_start_date.setText(bean.getStartDate());
//        holder.tv_plan_end_date.setText(bean.getEndDate());
//        holder.cb_item.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (itemCheckedChangeListener != null) {
//                    itemCheckedChangeListener.checkedChangeListener(position, holder.cb_item.isChecked());
//                }
//            }
//        });


        return convertView;
    }

    private class ViewHolder {
        private CheckBox cb_item;
        private TextView tv_content;
        private TextView tv_plan_start_date;
        private TextView tv_plan_end_date;

    }


}
